home *** CD-ROM | disk | FTP | other *** search
/ CD ROM Paradise Collection 4 / CD ROM Paradise Collection 4 1995 Nov.iso / arcers / tarsrc.zip / TARSRC.TAR / tar-1.11.2 / tar.h < prev    next >
C/C++ Source or Header  |  1993-11-15  |  10KB  |  297 lines

  1. /* Declarations for tar archives.
  2.    Copyright (C) 1988, 1992, 1993 Free Software Foundation
  3.  
  4. This file is part of GNU Tar.
  5.  
  6. GNU Tar is free software; you can redistribute it and/or modify
  7. it under the terms of the GNU General Public License as published by
  8. the Free Software Foundation; either version 2, or (at your option)
  9. any later version.
  10.  
  11. GNU Tar is distributed in the hope that it will be useful,
  12. but WITHOUT ANY WARRANTY; without even the implied warranty of
  13. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  14. GNU General Public License for more details.
  15.  
  16. You should have received a copy of the GNU General Public License
  17. along with GNU Tar; see the file COPYING.  If not, write to
  18. the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.  */
  19.  
  20. #include "testpad.h"
  21. #include "proto.h"
  22.  
  23. /* major() and minor() macros (among other things) defined here for hpux */
  24. #ifdef hpux
  25. #include <sys/mknod.h>
  26. #endif
  27.  
  28. /*
  29.  * Kludge for handling systems that can't cope with multiple
  30.  * external definitions of a variable.  In ONE routine (tar.c),
  31.  * we #define TAR_EXTERN to null; here, we set it to "extern" if
  32.  * it is not already set.
  33.  */
  34. #ifndef TAR_EXTERN
  35. #define TAR_EXTERN extern
  36. #endif
  37.  
  38. /*
  39.  * Header block on tape.
  40.  *
  41.  * I'm going to use traditional DP naming conventions here.
  42.  * A "block" is a big chunk of stuff that we do I/O on.
  43.  * A "record" is a piece of info that we care about.
  44.  * Typically many "record"s fit into a "block".
  45.  */
  46. #define    RECORDSIZE    512
  47. #define    NAMSIZ        100
  48. #define    TUNMLEN        32
  49. #define    TGNMLEN        32
  50. #define SPARSE_EXT_HDR  21
  51. #define SPARSE_IN_HDR    4
  52.  
  53. struct sparse
  54.   {
  55.     char offset[12];
  56.     char numbytes[12];
  57.   };
  58.  
  59. struct sp_array
  60.   {
  61.     int offset;
  62.     int numbytes;
  63.   };
  64.  
  65. union record
  66.   {
  67.     char charptr[RECORDSIZE];
  68.     struct header
  69.       {
  70.     char arch_name[NAMSIZ];
  71.     char mode[8];
  72.     char uid[8];
  73.     char gid[8];
  74.     char size[12];
  75.     char mtime[12];
  76.     char chksum[8];
  77.     char linkflag;
  78.     char arch_linkname[NAMSIZ];
  79.     char magic[8];
  80.     char uname[TUNMLEN];
  81.     char gname[TGNMLEN];
  82.     char devmajor[8];
  83.     char devminor[8];
  84.     /* these following fields were added by JF for gnu */
  85.     /* and are NOT standard */
  86.     char atime[12];
  87.     char ctime[12];
  88.     char offset[12];
  89.     char longnames[4];
  90. #ifdef NEEDPAD
  91.     char pad;
  92. #endif
  93.     struct sparse sp[SPARSE_IN_HDR];
  94.     char isextended;
  95.     char realsize[12];    /* true size of the sparse file */
  96.     /* char    ending_blanks[12];*//* number of nulls at the
  97.        end of the file, if any */
  98.       }
  99.     header;
  100.     struct extended_header
  101.       {
  102.     struct sparse sp[21];
  103.     char isextended;
  104.       }
  105.     ext_hdr;
  106.   };
  107.  
  108. /* The checksum field is filled with this while the checksum is computed. */
  109. #define    CHKBLANKS    "        "    /* 8 blanks, no null */
  110.  
  111. /* The magic field is filled with this if uname and gname are valid. */
  112. #define    TMAGIC        "ustar  "    /* 7 chars and a null */
  113.  
  114. /* The linkflag defines the type of file */
  115. #define    LF_OLDNORMAL    '\0'    /* Normal disk file, Unix compat */
  116. #define    LF_NORMAL    '0'    /* Normal disk file */
  117. #define    LF_LINK        '1'    /* Link to previously dumped file */
  118. #define    LF_SYMLINK    '2'    /* Symbolic link */
  119. #define    LF_CHR        '3'    /* Character special file */
  120. #define    LF_BLK        '4'    /* Block special file */
  121. #define    LF_DIR        '5'    /* Directory */
  122. #define    LF_FIFO        '6'    /* FIFO special file */
  123. #define    LF_CONTIG    '7'    /* Contiguous file */
  124. /* Further link types may be defined later. */
  125.  
  126. /* Note that the standards committee allows only capital A through
  127.    capital Z for user-defined expansion.  This means that defining something
  128.    as, say '8' is a *bad* idea. */
  129. #define LF_DUMPDIR    'D'    /* This is a dir entry that contains
  130.                        the names of files that were in
  131.                        the dir at the time the dump
  132.                        was made */
  133. #define LF_LONGLINK    'K'    /* Identifies the NEXT file on the tape
  134.                        as having a long linkname */
  135. #define LF_LONGNAME    'L'    /* Identifies the NEXT file on the tape
  136.                        as having a long name. */
  137. #define LF_MULTIVOL    'M'    /* This is the continuation
  138.                        of a file that began on another
  139.                        volume */
  140. #define LF_NAMES    'N'    /* For storing filenames that didn't
  141.                        fit in 100 characters */
  142. #define LF_SPARSE    'S'    /* This is for sparse files */
  143. #define LF_VOLHDR    'V'    /* This file is a tape/volume header */
  144. /* Ignore it on extraction */
  145.  
  146. /*
  147.  * Exit codes from the "tar" program
  148.  */
  149. #define    EX_SUCCESS    0    /* success! */
  150. #define    EX_ARGSBAD    1    /* invalid args */
  151. #define    EX_BADFILE    2    /* invalid filename */
  152. #define    EX_BADARCH    3    /* bad archive */
  153. #define    EX_SYSTEM    4    /* system gave unexpected error */
  154. #define EX_BADVOL    5    /* Special error code means
  155.                    Tape volume doesn't match the one
  156.                    specified on the command line */
  157.  
  158. /*
  159.  * Global variables
  160.  */
  161. TAR_EXTERN union record *ar_block;    /* Start of block of archive */
  162. TAR_EXTERN union record *ar_record;    /* Current record of archive */
  163. TAR_EXTERN union record *ar_last;    /* Last+1 record of archive block */
  164. TAR_EXTERN char ar_reading;    /* 0 writing, !0 reading archive */
  165. TAR_EXTERN int blocking;    /* Size of each block, in records */
  166. TAR_EXTERN int blocksize;    /* Size of each block, in bytes */
  167. TAR_EXTERN char *info_script;    /* Script to run at end of each tape change */
  168. TAR_EXTERN char *name_file;    /* File containing names to work on */
  169. TAR_EXTERN char filename_terminator;    /* \n or \0. */
  170. TAR_EXTERN char *tar;        /* Name of this program */
  171. TAR_EXTERN struct sp_array *sparsearray;    /* Pointer to the start of the scratch space */
  172. TAR_EXTERN int sp_array_size;    /* Initial size of the sparsearray */
  173. TAR_EXTERN int tot_written;    /* Total written to output */
  174. TAR_EXTERN struct re_pattern_buffer
  175.  *label_pattern;        /* compiled regex for extract label */
  176. TAR_EXTERN char **ar_files;    /* list of tape drive names */
  177. TAR_EXTERN int n_ar_files;    /* number of tape drive names */
  178. TAR_EXTERN int cur_ar_file;    /* tape drive currently being used */
  179. TAR_EXTERN int ar_files_len;    /* malloced size of ar_files */
  180. TAR_EXTERN char *current_file_name, *current_link_name;
  181.  
  182. /*
  183.  * Flags from the command line
  184.  */
  185. TAR_EXTERN int cmd_mode;
  186. #define CMD_NONE    0
  187. #define CMD_CAT        1    /* -A */
  188. #define CMD_CREATE    2    /* -c */
  189. #define CMD_DIFF    3    /* -d */
  190. #define CMD_APPEND    4    /* -r */
  191. #define CMD_LIST    5    /* -t */
  192. #define CMD_UPDATE    6    /* -u */
  193. #define CMD_EXTRACT    7    /* -x */
  194. #define CMD_DELETE    8    /* -D */
  195. #define CMD_VERSION    9    /* --version */
  196.  
  197.  
  198. TAR_EXTERN int f_reblock;    /* -B */
  199. #if 0
  200. TAR_EXTERN char f_dironly;    /* -D */
  201. #endif
  202. TAR_EXTERN int f_run_script_at_end;    /* -F */
  203. TAR_EXTERN int f_gnudump;    /* -G */
  204. TAR_EXTERN int f_follow_links;    /* -h */
  205. TAR_EXTERN int f_ignorez;    /* -i */
  206. TAR_EXTERN int f_keep;        /* -k */
  207. TAR_EXTERN int f_startfile;    /* -K */
  208. TAR_EXTERN int f_local_filesys;    /* -l */
  209. TAR_EXTERN int tape_length;    /* -L */
  210. TAR_EXTERN int f_modified;    /* -m */
  211. TAR_EXTERN int f_multivol;    /* -M */
  212. TAR_EXTERN int f_new_files;    /* -N */
  213. TAR_EXTERN int f_oldarch;    /* -o */
  214. TAR_EXTERN int f_exstdout;    /* -O */
  215. TAR_EXTERN int f_use_protection;/* -p */
  216. TAR_EXTERN int f_absolute_paths;/* -P */
  217. TAR_EXTERN int f_sayblock;    /* -R */
  218. TAR_EXTERN int f_sorted_names;    /* -s */
  219. TAR_EXTERN int f_sparse_files;    /* -S  ... JK */
  220. TAR_EXTERN int f_namefile;    /* -T */
  221. TAR_EXTERN int f_verbose;    /* -v */
  222. TAR_EXTERN char *f_volhdr;    /* -V */
  223. TAR_EXTERN int f_confirm;    /* -w */
  224. TAR_EXTERN int f_verify;    /* -W */
  225. TAR_EXTERN int f_exclude;    /* -X */
  226. TAR_EXTERN char *f_compressprog;    /* -z and -Z */
  227. TAR_EXTERN int f_do_chown;    /* --do-chown */
  228. TAR_EXTERN int f_totals;    /* --totals */
  229. TAR_EXTERN int f_remove_files;    /* --remove-files */
  230. TAR_EXTERN int f_ignore_failed_read;    /* --ignore-failed-read */
  231. TAR_EXTERN int f_checkpoint;    /* --checkpoint */
  232. TAR_EXTERN int f_show_omitted_dirs;    /* --show-omitted-dirs */
  233. TAR_EXTERN char *f_volno_file;    /* --volno-file */
  234. TAR_EXTERN int f_force_local;    /* --force-local */
  235. TAR_EXTERN int f_atime_preserve;/* --atime-preserve */
  236. TAR_EXTERN int f_compress_block; /* --compress-block */
  237.  
  238. /*
  239.  * We default to Unix Standard format rather than 4.2BSD tar format.
  240.  * The code can actually produce all three:
  241.  *    f_standard    ANSI standard
  242.  *    f_oldarch    V7
  243.  *    neither        4.2BSD
  244.  * but we don't bother, since 4.2BSD can read ANSI standard format anyway.
  245.  * The only advantage to the "neither" option is that we can cmp our
  246.  * output to the output of 4.2BSD tar, for debugging.
  247.  */
  248. #define        f_standard        (!f_oldarch)
  249.  
  250. /*
  251.  * Structure for keeping track of filenames and lists thereof.
  252.  */
  253. struct name
  254.   {
  255.     struct name *next;
  256.     short length;        /* cached strlen(name) */
  257.     char found;            /* A matching file has been found */
  258.     char firstch;        /* First char is literally matched */
  259.     char regexp;        /* This name is a regexp, not literal */
  260.     char *change_dir;        /* JF set with the -C option */
  261.     char *dir_contents;        /* JF for f_gnudump */
  262.     char fake;            /* dummy entry */
  263.     char name[1];
  264.   };
  265.  
  266. TAR_EXTERN struct name *namelist;    /* Points to first name in list */
  267. TAR_EXTERN struct name *namelast;    /* Points to last name in list */
  268.  
  269. TAR_EXTERN int archive;        /* File descriptor for archive file */
  270. TAR_EXTERN int errors;        /* # of files in error */
  271.  
  272. TAR_EXTERN char *gnu_dumpfile;
  273.  
  274. /*
  275.  * Error recovery stuff
  276.  */
  277. TAR_EXTERN char read_error_flag;
  278.  
  279.  
  280. /*
  281.  * Declarations of functions available to the world.
  282.  */
  283. #ifndef USE_PROTOTYPES
  284. union record *findrec _P_((void));
  285. void userec _P_((union record *rec));
  286. union record *endofrecs _P_((void));
  287. void anno _P_((FILE *stream, char *prefix, int savedp));
  288.  
  289. #ifdef HAVE_VPRINTF
  290. void msg _P_((char *, ...));
  291. void msg_perror _P_((char *, ...));
  292. #else
  293. void msg ();
  294. void msg_perror ();
  295. #endif
  296. #endif
  297.